package com.zking.dao.mapper;

import org.apache.ibatis.annotations.*;

import com.zking.dao.domain.SysRole;

import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;
import java.util.Set;

@Repository
public interface SysRoleMapper extends Mapper<SysRole> {
    @Select("SELECT sr.role_desc FROM sys_user_role sur LEFT JOIN sys_role sr ON sr.id = sur.role_id \n" +
            "LEFT JOIN sys_user su ON sur.user_id = su.id WHERE su.id = #{userId}")
    Set<String> findRoleNameByUserId(@Param("userId") int userId);

    @Select("SELECT sr.* FROM `sys_user_role` sur, sys_user su, sys_role sr\n" +
            "where sur.role_id = sr.id and sur.user_id = su.id\n" +
            "and su.id = #{id}")
    @ResultMap("BaseResultMap")
    List<SysRole> findRolesByUserId(Integer id);
}